package com.example.springioc.controller;

import com.example.springioc.entity.User;
import com.example.springioc.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

@Controller
@Service
public class UserController {
//    注入方法1:属性注入
    @Autowired
    private UserService userService;

//    @Qualifier("u1")
//    @Autowired
    @Resource(name = "u2")
    private User user;

//    注入方法2:构造方法注入
//    @Autowired
//    public UserController(UserService userService) {
//        this.userService = userService;
//    }

//    注入方法3:Setter方法注入
//    @Autowired
//    public void setUserService(UserService userService) {
//        this.userService = userService;
//    }

    public void sayHi() {
        System.out.println("Hi, I am UserController!");
        userService.sayHi();
        System.out.println(user);
    }
}
